package com.aiyige.page.selectinterest.util;

import com.aiyige.page.selectinterest.model.IndustryItem;
import com.aiyige.utils.AccountUtil;
import com.aiyige.utils.ListUtil;
import com.aiyige.utils.PreferenceUtil;
import com.alibaba.fastjson.JSON;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by zhuyakun on 2017/10/30.
 */

public class InterestUtil {
    public static String PREF_KEY_INTEREST_ID_PREFIX = "com.aiyige.pref.PREF_KEY_INTEREST_ID_PREFIX";
    public static String PREF_KEY_INTEREST_NAME_PREFIX = "com.aiyige.pref.PREF_KEY_INTEREST_NAME_PREFIX";
    public static String PREF_KEY_INDUSTRY_ID_PREFIX = "com.aiyige.pref.PREF_KEY_INDUSTRY_ID_PREFIX";
    public static String PREF_KEY_INDUSTRY_NAME_PREFIX = "com.aiyige.pref.PREF_KEY_INDUSTRY_NAME_PREFIX";
    public static String PREF_KEY_INTEREST_SELECT_STATE_PREFIX = "com.aiyige.pref.PREF_KEY_INTEREST_SELECT_STATE_PREFIX";

    public static void setInterestId(List<String> interestIdList) {
        String json = ListUtil.isEmpty(interestIdList) ? "" : JSON.toJSONString(interestIdList);
        PreferenceUtil.putString(PREF_KEY_INTEREST_ID_PREFIX, json);
    }

    public static List<String> getInterestId() {
        return new LinkedList<>();
//        try {
//            String json = PreferenceUtil.getString(PREF_KEY_INTEREST_ID_PREFIX , "");
//            List<String> interestIdList = JSON.parseArray(json, String.class);
//            if (ListUtil.isEmpty(interestIdList)) {
//                return new LinkedList<>();
//            } else {
//                return interestIdList;
//            }
//        } catch (Exception e) {
//            return new LinkedList<>();
//        }
    }

    public static void setInterestName(List<String> interestNameList) {
        String json = ListUtil.isEmpty(interestNameList) ? "" : JSON.toJSONString(interestNameList);
        PreferenceUtil.putString(PREF_KEY_INTEREST_NAME_PREFIX, json);
    }

    public static List<String> getInterestName() {
        return new LinkedList<>();
//        try {
//            String json = PreferenceUtil.getString(PREF_KEY_INTEREST_NAME_PREFIX, "");
//            List<String> interestNameList = JSON.parseArray(json, String.class);
//            if (ListUtil.isEmpty(interestNameList)) {
//                return new LinkedList<>();
//            } else {
//                return interestNameList;
//            }
//        } catch (Exception e) {
//            return new LinkedList<>();
//        }
    }

    public static void setInterestSelectState(List<IndustryItem> list) {
        String json = ListUtil.isEmpty(list) ? "" : JSON.toJSONString(list);
        PreferenceUtil.putString(PREF_KEY_INTEREST_SELECT_STATE_PREFIX, json);
    }

    public static List<IndustryItem> getInterestSelectState() {
        return new LinkedList<>();
//        try {
//            String json = PreferenceUtil.getString(PREF_KEY_INTEREST_SELECT_STATE_PREFIX, "");
//            List<IndustryItem> industryItemList = JSON.parseArray(json, IndustryItem.class);
//            if (ListUtil.isEmpty(industryItemList)) {
//                return new LinkedList<>();
//            } else {
//                return industryItemList;
//            }
//        } catch (Exception e) {
//            return new LinkedList<>();
//        }
    }

    public static void setIndustryId(List<String> industryIdList) {
        String json = ListUtil.isEmpty(industryIdList) ? "" : JSON.toJSONString(industryIdList);
        PreferenceUtil.putString(PREF_KEY_INDUSTRY_ID_PREFIX, json);
    }

    public static List<String> getIndustryId() {
        return new LinkedList<>();
//        try {
//            String json = PreferenceUtil.getString(PREF_KEY_INDUSTRY_ID_PREFIX, "");
//            List<String> industryIdList = JSON.parseArray(json, String.class);
//            if (ListUtil.isEmpty(industryIdList)) {
//                return new LinkedList<>();
//            } else {
//                return industryIdList;
//            }
//        } catch (Exception e) {
//            return new LinkedList<>();
//        }
    }

    public static void setIndustryName(List<String> industryNameList) {
        String json = ListUtil.isEmpty(industryNameList) ? "" : JSON.toJSONString(industryNameList);
        PreferenceUtil.putString(PREF_KEY_INDUSTRY_NAME_PREFIX, json);
    }

    public static List<String> getIndustryName() {
        return new LinkedList<>();
//        try {
//            String json = PreferenceUtil.getString(PREF_KEY_INDUSTRY_NAME_PREFIX, "");
//            List<String> industryNameList = JSON.parseArray(json, String.class);
//            if (ListUtil.isEmpty(industryNameList)) {
//                return new LinkedList<>();
//            } else {
//                return industryNameList;
//            }
//        } catch (Exception e) {
//            return new LinkedList<>();
//        }
    }


}